package generic;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-02-20
 * Time:15:17
 */
class Myarray<E extends Number>{//E可以是Number或者Number的子类 这就是泛型的上界泛型没有下界 没有指定边界的话上界默认就是Object
    public E[] objects = (E[]) new Object[10];
    public void set(int pos,E val){
        objects[pos] = val;
    }
    public E get(int pos){
        return objects[pos];
    }
}

public class Boundary {
    public static void main(String[] args) {
        Myarray<Integer> l1 = new Myarray<>();
        Myarray<Double> l2 = new Myarray<>();
        Myarray<Number> l3 = new Myarray<>();
        //Myarray<String> l3 = new Myarray<>();//这样就会报错 String不是Number的子类
        l1.set(0,1);
        l2.set(0,1.2);
        l3.set(0,2);//此时Number类型下的都可以放
    }
}
